package net.oschina.app.factory;


import android.os.Bundle;
import android.support.v4.app.Fragment;

import net.oschina.app.fragment.NewsBlogFragment;
import net.oschina.app.fragment.NewsInfosFragment;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by wei03 on 2017/1/13.
 */

public class NewsFragmentFactory extends BaseFactory{
    public  Fragment getFragment(int position) {
        Map<Integer, Fragment> fragments = new HashMap<>();
        Fragment fragment  = fragments.get(position);
        if (fragment == null) {
            switch (position) {
                case 0:
                    fragment = new NewsInfosFragment();
                    Bundle infos = new Bundle();
                    infos.putString("type","infos");
                    fragment.setArguments(infos);
                    break;
                case 1:
                    fragment = new NewsInfosFragment();
                    Bundle hotspot= new Bundle();
                    hotspot.putString("type","hotspot");
                    fragment.setArguments(hotspot);
                    break;
                case 2:
                    fragment = new NewsBlogFragment();
                    Bundle bundle = new Bundle();
                    bundle.putString("type","latest");
                    fragment.setArguments(bundle);
                    break;
                case 3:
                    fragment = new NewsBlogFragment();
                    Bundle recommend = new Bundle();
                    recommend.putString("type","recommend");
                    fragment.setArguments(recommend);
                    break;
                default:
                    fragment = new NewsInfosFragment();
            }
            fragments.put(position, fragment);
        }
        return fragment;
    }
}
